package com.onlyMe.view.world.tiling
{
	import com.onlyMe.config.tiles.TilesNode;
	import com.onlyMe.globals.config;
	import com.qb9.flashlib.color.Color;
	import com.qb9.flashlib.geom.Anchor;
	import com.qb9.flashlib.prototyping.shapes.BasicShapeConfig;
	import com.qb9.flashlib.prototyping.shapes.Parallelogram;
	import com.qb9.flashlib.prototyping.shapes.Rect;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Matrix;

	// TODO: Create TileProto or something like that and pass it to Tiles
	
	public final class TileAssetCreator
	{
		private var bd:BitmapData;
		private var matrix:Matrix;
		
		public function TileAssetCreator()
		{
		}
		
		// TEMP
		public function create2(type:String):DisplayObject
		{
			var t:TilesNode = config.tiles;

			if (!bd) {
				var asset:Sprite = new Rect(t.width, t.height, new BasicShapeConfig(Color.YELLOW, 1, 1));
				bd = new BitmapData(t.width, t.height);
				bd.draw(asset);
				matrix = new Matrix();
				matrix.b = Math.tan(-0.5);
			}
			
			var bmp:Bitmap = new Bitmap(bd);
			bmp.transform.matrix = matrix;
			return bmp;
		}
		
		public function create(type:String):DisplayObject
		{
			var t:TilesNode = config.tiles;

			return new Parallelogram(
				t.width, t.height, t.angle, 
				new BasicShapeConfig(Color.YELLOW, 1, 1), 
				Anchor.center
			);
		}
	}
}